package util
{

	import flash.display.DisplayObject;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;

	public class ColorUtil
	{

		public static const FONT_BROWN:uint = 0x86593e;

		public static function shine(target:DisplayObject):void
		{
			var color:ColorTransform = new ColorTransform(1.2, 1.2, 1.2);
			target.transform.colorTransform = color;
		}

		public static function disable(target:DisplayObject):void
		{
			var color:ColorTransform = new ColorTransform(1.2, 1.2, 1.2);
			target.transform.colorTransform = color;
		}

		public static function normal(target:DisplayObject):void
		{
			target.transform.colorTransform = new ColorTransform();
		}

		private static var defaultTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
		private static var highLightTransform:ColorTransform = new ColorTransform(1, 1, 1, 1, 50, 50, 0, 0);

		/**高度**/
		public static function highLight(displayObject:DisplayObject):void
		{
			displayObject.transform.colorTransform = highLightTransform;
		}

		/**正常亮度**/
		public static function darkLight(displayObject:DisplayObject):void
		{
			displayObject.transform.colorTransform = defaultTransform;
		}

		/**添加边框颜色**/
		public static function addColorRing(target:DisplayObject, color:uint = 0xFFFFFF, blurX:Number = 3, blurY:Number = 3, strength:Number = 6):void
		{
			var gfilter:GlowFilter;

			if(target)
			{
				var curFilters:Array = target.filters;

				for(var i:int = 0; i < curFilters.length; i++)
				{
					if(curFilters[i] is GlowFilter)
					{
						gfilter = curFilters[i];
						break;
					}
				}

				if(gfilter)
				{
					gfilter.color = color;
				}
				else
				{
					gfilter = new GlowFilter(color, 1, blurX, blurY, strength, 2);
					curFilters.push(gfilter);
				}
				target.filters = curFilters;
			}
		}

		/**取消边框颜色**/
		public static function removeColorRing(target:DisplayObject):void
		{
			if(target && target.filters)
			{
				var curFilters:Array = target.filters;

				for(var i:int = 0; i < curFilters.length; i++)
				{
					if(curFilters[i] is GlowFilter)
					{
						curFilters.splice(i, 1);
						target.filters = curFilters;
						break;
					}
				}
			}
		}

		private static var _blackColorMatrix:ColorMatrixFilter = new ColorMatrixFilter([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
		private static var _nomalColorMatrix:ColorMatrixFilter = new ColorMatrixFilter([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]);

		/**设置显示对象成黑白色**/
		public static function setBlackColor(target:DisplayObject):void
		{
			target.filters = [_blackColorMatrix];
		}

		public static function setDefaultColor(target:DisplayObject):void
		{
			target.filters = [_nomalColorMatrix];
		}
	}
}